import tushare as ts
from sqlalchemy import create_engine
from sqlalchemy.orm import sessionmaker
import OracleUtils
from mapper.pojo import StockInfo
from database import sqlUtils


class DayStockAll(object):
    def __init__(self):
        self.pro = ts.pro_api()

    def update_stock_all(self):
        data = self.pro.query('stock_basic', list_status='L')
        # 创建会话
        session = sqlUtils.get_sqlalchemy_session()
        d_len = data.shape[0]
        for i in range(d_len):
            row = list(data.iloc[i])
            stock_info = StockInfo.tranfer(row)
            session.merge(stock_info)
            session.commit()
        session.close()
        print("股票列表已更新")


ts.set_token("f69287e7ed3a204a5edb6d6c851fd8d7709aa10cdeac741db751aa94")
day_stock = DayStockAll()
day_stock.update_stock_all()
